<template>
  <div class="tchart-content" id="temChart">
    <div style="flex: 1;">
      <div style="padding: 10px;min-width: 200px;">
        <el-button type="danger" v-for="(item,index) in optionsKey"  :key="index" style="margin: 5px;">{{item.operName}}</el-button>
      </div>
      <el-row type="flex" justify="start">
        <el-col :span="12" class="descrip">
          <i class="iconfont icon-wenhao" style="font-size: 26px;margin-bottom: 5px;"></i>
          查看说明
        </el-col>
        <el-col :span="6">
          <div class="time-show">{{this.time}}</div>
        </el-col>
      </el-row>
    </div>
    <div style="flex: 3;">
      <Charts :tempData="tempData"></Charts>
    </div>
  </div>
</template>

<script>
  import EquipTypeApi from '@/api/equipType'
  import Charts from './charts'
  export default{
    props:{
      theEquipId:String
    },
    data(){
      return{
        time:'',
        // 操作键
        optionsKey:[],
        // 温度数据
        tempData:{}
      }
    },
    watch:{
      deep:true,
      theEquipId:function(newV,oldV){
        this.theEquipId = newV
        this.getTheData()
      }
    },
    components:{
      Charts
    },
    created() {
      let timer = setInterval(()=> {
        var date = new Date()
        if(date.getMinutes())
        // this.time = this.addZero(date.getHours()) +":"+ this.addZero(date.getMinutes()) +":"+ this.addZero(date.getSeconds())
        this.time = this.addZero(date.getHours()) +":"+ this.addZero(date.getMinutes())
      },1000)
      this.$once('hook:beforeDestroy', function() {
          clearInterval(timer)
      })
      // 获取数据
      this.getTheData()
    },
    methods:{
      addZero(num){
        if(num < 10){
          return "0"+num
        }
        return num
      },
      getTheData(){
        // 获取温度数据
        EquipTypeApi.getTemporData(this.theEquipId).then(res => {
          // 获取温度传感器
          res.data.data.map(val => {
            if(val.sensorType === '2'){
              this.tempData = val
            }
          })
        })

        // 获取操作键
        EquipTypeApi.getEquipOption(this.theEquipId).then(res => {
          if(res.data.status === "200"){
            this.optionsKey = res.data.data.records
          }
        })
      }
    },
  }
</script>

<style scoped="scoped">
  .tchart-content{
    /* padding: 5px 10px; */
    height: 30vh;
    display: flex;
    border-bottom: 1px solid #000b2b;
  }
  .row-bg {
    padding: 10px 0;
  }
  #temChart .el-button{
    border: 1px solid #a3a196;
  }
  #temChart .el-button:focus, .el-button:hover{
    /* color: #409EFF; */
    /* border-color: #c6e2ff; */
    background-color: #bdd0fe;
  }
  .time-show{
    /* width: 100px; */
    height: 40px;
    box-shadow: -1px -1px 3px #909399;
    border-right: 1px solid #FFFFFF;
    border-bottom: 1px solid #FFFFFF;
    line-height: 40px;
    text-align: center;
    font-family:digital-7;
    background-color: rgb(238, 235, 220);
    color: blue;
    font-size: 25px;
  }
  .descrip{
    text-align: center;
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: red;
  }
</style>
